<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>阴影</title>
</head>
<body>
  <canvas id="drawing" width="200" height="200"></canvas>
  <script>
    const drawing = document.getElementById('drawing');

    // 确保浏览器支持 <canvas>
    if (drawing.getContext) {
      const context = drawing.getContext('2d');

      // 设置阴影
      context.shadowOffsetX = 5;
      context.shadowOffsetY = 5;
      context.shadowBlur = 4;
      context.shadowColor = 'rgba(0, 0, 0, 0.5)';
      // 绘制红色矩形
      context.fillStyle = '#ff0000';
      context.fillRect(10, 10, 50, 50);
      // 绘制蓝色矩形
      context.fillStyle = '#0000ff';
      context.fillRect(30, 30, 50, 50);
    }
  </script>
</body>
</html>